# 基础镜像
FROM registry.cn-hangzhou.aliyuncs.com/dwyanewang/bookworm-node-bun:slim-20.15.0-1.1.17 as base
WORKDIR /root/rms

COPY package.json ./


# 安装依赖
FROM base as install

COPY bun.lockb ./
COPY prisma ./prisma
COPY .env ./

RUN bun install && bunx prisma generate


# 项目打包
FROM base as builder

COPY --from=install /root/rms/node_modules  ./node_modules
COPY src ./src
COPY build.ts ./

RUN bun run build

# 构建制品镜像
FROM base

COPY --from=install /root/rms/node_modules/.prisma  ./node_modules/.prisma
COPY --from=install /root/rms/node_modules/@prisma  ./node_modules/@prisma
COPY --from=builder /root/rms/out  ./out
COPY .env ./

VOLUME ["/root/rms/logs"]
VOLUME ["/root/rms/static"]

EXPOSE 8890

CMD bun run start